package com.android.place360;

import java.util.ArrayList;

import com.android.place360.database.Catalog;
import com.android.place360.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomAdapter extends BaseAdapter {
	private Context mContext;
	ArrayList<Catalog> lstItems;

	public CustomAdapter(Context c, ArrayList<Catalog> lstItems) {
		mContext = c;
		this.lstItems = lstItems;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lstItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return lstItems.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View grid;

		if (convertView == null) {
			grid = new View(mContext);
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			grid = inflater.inflate(R.layout.i_custom_gridview, parent, false);
		} else {
			grid = (View) convertView;
		}

		ImageView imageView = (ImageView) grid
				.findViewById(R.id.i_custom_gridview_imageview);
		imageView.setImageResource(lstItems.get(position).getIcon());
		
		TextView textView = (TextView) grid.findViewById(R.id.gridView_name);
		textView.setText(lstItems.get(position).getName());

		return grid;
	}
}
